import { resolve } from 'path'
// 首先需要安装vite，在终端中运行以下命令
// npm install vite --save-dev 或者 yarn add vite --dev
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import viteBasicSslPlugin from '@vitejs/plugin-basic-ssl'
import { createStyleImportPlugin, VxeTableResolve } from 'vite-plugin-style-import'
import autoprefixer from 'autoprefixer'
// @ts-ignore
import postCssPxToRem from 'postcss-pxtorem'
import tailwindcss from '@tailwindcss/vite'
// https://vitejs.dev/config/
export default defineConfig({
  // 避免打包访问后空白页面，需要设置base为"./"
  base: './',
  plugins: [
    vue({}),
    viteBasicSslPlugin(), // 添加后https证书可以自动生成
    createStyleImportPlugin({
      resolves: [VxeTableResolve()]
    }),
    tailwindcss()
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  optimizeDeps: {
    exclude: ['@babylonjs/havok'] // 避免 Vite 预构建 Havok
  },
  server: {
    host: '0.0.0.0',
    port: 20001
    // https: false, // 使用了viteBasicSslPlugin插件后，无需再设置https为true

  },
  css: {
    modules: {},
    preprocessorOptions: {
      less: {
        math: 'always'
      }
    },
    postcss: {
      plugins: [
        postCssPxToRem({ // 自适应，px>rem转换
          rootValue: 16, // 1rem的大小
          propList: ['*'] // 需要转换的属性，这里选择全部都进行转换
        }),
        autoprefixer({
          overrideBrowserslist: [
            '>99.8%'
          ]
        })
      ]
    }
  },
  assetsInclude: ['public/**/*.gltf', 'public/**/*.{bin, glb}', 'src/**/*.{png,jpg,jpeg,hdr}']
})
